package com.ruoyi.web.invest.asset.feedback.service.impl;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.framework.web.service.TokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.web.invest.asset.feedback.mapper.FeedBackMapper;
import com.ruoyi.web.operate.stock.mapper.StockMapper;
import com.ruoyi.web.invest.asset.feedback.domain.FeedBack;
import com.ruoyi.web.invest.asset.feedback.service.IFeedBackService;

/**
 * 阶段性反馈Service业务层处理
 *
 * @author houxuzhong
 * @date 2021-08-26
 */
@Service
public class FeedBackServiceImpl implements IFeedBackService
{
    @Autowired
    private FeedBackMapper feedBackMapper;
    @Autowired
    private StockMapper stockMapper;
    @Autowired
    private TokenService tokenService;

    /**
     * 查询阶段性反馈
     *
     * @param id 阶段性反馈主键
     * @return 阶段性反馈
     */
    @Override
    public FeedBack selectFeedBackById(Long id)
    {
        return feedBackMapper.selectFeedBackById(id);
    }

    /**
     * 查询阶段性反馈列表
     *
     * @param feedBack 阶段性反馈
     * @return 阶段性反馈
     */
    @Override
    public List<FeedBack> selectFeedBackList(FeedBack feedBack)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        SysUser user = loginUser.getUser();
        feedBack.setCreateById(user.getUserId());
        feedBack.setCreateBy(user.getUserName());
        return feedBackMapper.selectFeedBackList(feedBack);
    }

    /**
     * 新增阶段性反馈
     *
     * @param feedBack 阶段性反馈
     * @return 结果
     */
    @Override
    public int insertFeedBack(FeedBack feedBack)
    {
        feedBack.setCreateTime(DateUtils.getNowDate());
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        SysUser user = loginUser.getUser();
        feedBack.setCreateById(user.getUserId());
        feedBack.setCreateBy(user.getUserName());
        feedBack.setStockOwnerid(stockMapper.selectOwnerIdByStockCode(feedBack.getStockCode()));
        return feedBackMapper.insertFeedBack(feedBack);
    }

    /**
     * 修改阶段性反馈
     *
     * @param feedBack 阶段性反馈
     * @return 结果
     */
    @Override
    public int updateFeedBack(FeedBack feedBack)
    {
        feedBack.setUpdateTime(DateUtils.getNowDate());
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        SysUser user = loginUser.getUser();
        feedBack.setUpdateById(user.getUserId());
        feedBack.setUpdateBy(user.getUserName());
        return feedBackMapper.updateFeedBack(feedBack);
    }

    /**
     * 批量删除阶段性反馈
     *
     * @param ids 需要删除的阶段性反馈主键
     * @return 结果
     */
    @Override
    public int deleteFeedBackByIds(Long[] ids)
    {
        return feedBackMapper.deleteFeedBackByIds(ids);
    }

    /**
     * 删除阶段性反馈信息
     *
     * @param id 阶段性反馈主键
     * @return 结果
     */
    @Override
    public int deleteFeedBackById(Long id)
    {
        return feedBackMapper.deleteFeedBackById(id);
    }
}
